/*
 * @lc app=leetcode.cn id=229 lang=cpp
 *
 * [229] 多数元素 II
 */

// @lc code=start
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
    vector<int> majorityElement(vector<int> &nums)
    {
        map<int, int> m;
        for (auto n : nums)
            m[n]++;
        
        const int low_bound = nums.size() / 3;
        
        vector<int> ans;
        for(auto& n : m)
        {
            if(n.second > low_bound)
            {
                ans.push_back(n.first);
            }
        }
        return ans;
    }
};
// @lc code=end
